package cn.com.shopec.erp.product.commo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.com.shopec.erp.common.constant.SZSCMConstant;
import cn.com.shopec.erp.common.utils.DateUtil;
import cn.com.shopec.erp.common.utils.RandomUtil;
import cn.com.shopec.erp.product.entity.SpecValOption;
import cn.com.shopec.erp.product.entity.Specification;
import cn.com.shopec.erp.product.model.SpecValOptionInfo;
import cn.com.shopec.erp.product.model.SpecificationDetail;
import cn.com.shopec.erp.product.model.SpecificationInfo;

/** 
 * @ClassName: SpecPropertyUtils 
 * @Description: 货品规格相关对象转换工具类
 *  
 */

public class SpecPropertyUtils {
	
	/** 
	 * @Title: getSpecificationInfo 
	 * @Description: 将Specification实体对象，转为SpecificationInfo对象
	 * @param p
	 * @return  
	 * @throws 
	 */
	public static SpecificationInfo getSpecificationInfo(Specification p) {
		SpecificationInfo o = null;
		if(p != null) {
			o = new SpecificationInfo();
			o.setSpecNo(p.getSpecNo());
			o.setSpecName(p.getSpecName());
			o.setCatNo(p.getCatNo());
		}
		return o;
	}
	
	/** 
	 * @Title: getSpecificationInfoList 
	 * @Description: 将Specification实体对象列表，转为SpecificationInfo对象列表
	 * @param pList
	 * @return  
	 * @throws 
	 */
	public static List<SpecificationInfo> getSpecificationInfoList(List<Specification> pList) {
		List<SpecificationInfo> oList = new ArrayList<SpecificationInfo>(pList == null ? 0 : pList.size());
		if(pList != null) {
			for(Specification p : pList) {
				oList.add(getSpecificationInfo(p));
			}
		}
		
		return oList;
	}
	
	/** 
	 * @Title: getSpecificationDetail 
	 * @Description: 将Specification对象，转为SpecificationDetail对象
	 * @param p
	 * @return  
	 * @throws 
	 */
	public static SpecificationDetail getSpecificationDetail(Specification p) {
		SpecificationDetail o = null;
		if(p != null) {
			o = new SpecificationDetail();
			o.setCatNo(p.getCatNo());
			o.setSpecNo(p.getSpecNo());
			o.setSpecName(p.getSpecName());
			
			o.setSpecValOptions(getSpecValOptionInfoList(p.getOptions()));
		}
		return o;
	}
	
	/** 
	 * @Title: getSpecificationDetailList 
	 * @Description: 将Specification对象的列表，转为SpecificationDetail对象的列表
	 * @param pList
	 * @return  
	 * @throws 
	 */
	public static List<SpecificationDetail> getSpecificationDetailList(List<Specification> pList) {
		List<SpecificationDetail> oList = new ArrayList<SpecificationDetail>(pList == null ? 0 : pList.size()); 
		if(pList != null) {
			for(Specification p : pList) {
				oList.add(getSpecificationDetail(p));
			}
		}
		
		return oList;
	}
	
	/** 
	 * @Title: getSpecification 
	 * @Description: 将SpecificationInfo对象，转为Specification实体对象
	 * @param p
	 * @return  
	 * @throws 
	 */
	public static Specification getSpecification(SpecificationInfo p) {
		Specification o = null;
		if(p != null) {
			o = new Specification();
			o.setCatNo(p.getCatNo());
			o.setSpecNo(p.getSpecNo());
			o.setSpecName(p.getSpecName());
			o.setDeleteFlag(SZSCMConstant.DELETE_FLAG_NO);
			o.setCreateTime(DateUtil.formatDateByFormat(new Date(), DateUtil.TIMESTAMP_PATTERN));
			o.setUpdateTime(o.getCreateTime());
		}
		return o;
	}
	
	/** 
	 * @Title: getSpecValOption 
	 * @Description: 将SpecValOptionInfo对象，转为SpecValOption实体对象
	 * @param p
	 * @return  
	 * @throws 
	 */
	public static SpecValOption getSpecValOption(SpecValOptionInfo p) {
		SpecValOption o = null;
		if(p != null) {
			o = new SpecValOption();
			o.setSpecNo(p.getSpecNo());
			o.setOptionNo(p.getOptionNo());
			o.setOptionName(p.getOptionName());
			o.setDeleteFlag(SZSCMConstant.DELETE_FLAG_NO);
			o.setCreateTime(DateUtil.formatDateByFormat(new Date(), DateUtil.TIMESTAMP_PATTERN));
			o.setUpdateTime(o.getCreateTime());
		}
		return o;
	}
	
	/** 
	 * @Title: getSpecValOptionList 
	 * @Description: 将SpecValOptionInfo对象的列表，转为SpecValOption实体对象的列表
	 * @param pList
	 * @return  
	 * @throws 
	 */
	public static List<SpecValOption> getSpecValOptionList(List<SpecValOptionInfo> pList) {
		List<SpecValOption> oList = new ArrayList<SpecValOption>(pList == null ? 0 : pList.size());
		if(pList != null) {
			for(SpecValOptionInfo p : pList) {
				oList.add(getSpecValOption(p));
			}
		}
		return oList;
	}
	
	/** 
	 * @Title: getSpecValOptionInfo 
	 * @Description: 将SpecValOption对象，转为SpecValOptionInfo对象
	 * @param p
	 * @return  
	 * @throws 
	 */
	public static SpecValOptionInfo getSpecValOptionInfo(SpecValOption p) {
		SpecValOptionInfo o = null;
		if(p != null) {
			o = new SpecValOptionInfo();
			o.setSpecNo(p.getSpecNo());
			o.setOptionNo(p.getOptionNo());
			o.setOptionName(p.getOptionName());
		}
		return o;
	}
	
	/** 
	 * @Title: getSpecValOptionInfoList 
	 * @Description: 将SpecValOption对象的列表，转为SpecValOptionInfo对象的列表
	 * @param pList
	 * @return  
	 * @throws 
	 */
	public static List<SpecValOptionInfo> getSpecValOptionInfoList(List<SpecValOption> pList) {
		List<SpecValOptionInfo> oList = new ArrayList<SpecValOptionInfo>(pList == null ? 0 : pList.size()); 
		if(pList != null) {
			for(SpecValOption p : pList) {
				if(p.getDeleteFlag() != SZSCMConstant.DELETE_FLAG_YES)
					oList.add(getSpecValOptionInfo(p));
			}
		}

		return oList;
	}
	
	/** 
	 * @Title: genSpecificationNo 
	 * @Description: 生成规格编号
	 * @return  
	 * @throws 
	 */
	public static String genSpecificationNo() {
		//TODO 
		String no = "SP" + DateUtil.formatDateByFormat(new Date(), DateUtil.NOCHAR_PATTERN) + RandomUtil.getRandomNumberStr(5);
		
		return no;
	}
	
	/** 
	 * @Title: genSpecValOptionNo 
	 * @Description: 生成规格值选项的编号
	 * @return  
	 * @throws 
	 * @author: lule
	 * @date: 2013-5-30下午5:21:41
	 */
	public static String genSpecValOptionNo() {
		//TODO 
		String no = "SPV" + DateUtil.formatDateByFormat(new Date(), DateUtil.NOCHAR_PATTERN) + RandomUtil.getRandomNumberStr(5);
		
		return no;
	}
}
